Repository navigation
Conversation
wait() writes the flag from the calling thread while the worker thread reads it in its loop condition. ThreadSanitizer reports this as a data race on an idle writer. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
|
@SteveBronder while adding the pathfinder concurrent writer in #3325 were there any specific benchmarks you were running that would be good to re-run with this change? |
|
@viftode4 Thanks for the PR. Would you mind removing the |
|
@viftode4: Sorry about this, but we've been hashing out our AI policy. None of this is about your PR per se. @WardBrian If our policy is going to be to forbid Claude attributions in headers, maybe we could cut them off at the pass by blocking commits that are by "X and Claude". Or maybe some kind of hook in PRs that looks for this boilerplate? I don't know if there's a way to get commits made by Claude to not include the self attribution, but if so, we should indicate that to users if this is our policy by pointing them to Claude's doc. It would be great if these automatic rejections could point to an explicit piece of our AI policy. It's not clear to me, at least, that this PR violates our policies. |
|
Another thing to flag in this PR is the copyright. Are we running into legal issues accepting PRs attributed to GitHub accounts? That's not how copyright works. It gets assigned to the person who authored the content or to whatever legal entity they assign their copyright to. I do not believe GitHub accounts are legitimate copyright holders. This is not the only case of this we have as not all of our developers have identified themselves "in real life." |
Jenkins Console Log Machine informationDistributor ID: Ubuntu Description: Ubuntu 20.04.3 LTS Release: 20.04 Codename: focal CPU: Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Byte Order: Little Endian Address sizes: 52 bits physical, 57 bits virtual CPU(s): 192 On-line CPU(s) list: 0-191 Thread(s) per core: 2 Core(s) per socket: 48 Socket(s): 2 NUMA node(s): 2 Vendor ID: AuthenticAMD CPU family: 25 Model: 17 Model name: AMD EPYC 9474F 48-Core Processor Stepping: 1 Frequency boost: enabled CPU MHz: 1497.373 CPU max MHz: 4114.4229 CPU min MHz: 1500.0000 BogoMIPS: 7189.43 Virtualization: AMD-V L1d cache: 3 MiB L1i cache: 3 MiB L2 cache: 96 MiB L3 cache: 512 MiB NUMA node0 CPU(s): 0-47,96-143 NUMA node1 CPU(s): 48-95,144-191 Vulnerability Gather data sampling: Not affected Vulnerability Indirect target selection: Not affected Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Not affected Vulnerability Old microcode: Not affected Vulnerability Reg file data sampling: Not affected Vulnerability Retbleed: Not affected Vulnerability Spec rstack overflow: Mitigation; Safe RET Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsa: Mitigation; Clear CPU buffers Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Mitigation; IBPB before exit to userspace Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good amd_lbr_v2 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d debug_swap G++: g++ (Ubuntu 9.4.0-1ubuntu1~20.04) 9.4.0 Copyright (C) 2019 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Clang: clang version 10.0.0-4ubuntu1 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin |
Summary
Make
concurrent_writer::continue_writing_astd::atomic<bool>. Fixes #3464.Intended Effect
wait()writes the flag from the calling thread while the worker reads it in its loop condition. That is a data race under the C++ memory model, and ThreadSanitizer reports it for a writer that is constructed and then waited on. The change removes the report. Behaviour is otherwise unchanged.wait()still sets the flag and then joins. The worker loop is unchanged.On @WardBrian's question in the issue: on x86 I do not expect a visible failure. The worker's loop has opaque calls (
try_pop,yield), so the compiler is unlikely to hoist the load. The race is formally undefined behaviour, and it makes TSan builds of any Stan program using threaded output fail, so a one-line atomic seemed cheap. Close this if you would rather not take it.How to Verify
Reporter's program from #3464 (construct a
concurrent_writer, callwait()), built with-O1 -g -fsanitize=thread -DSTAN_THREADS, GCC 13.3, Ubuntu 24.04 x86-64, unmodifieddevelopagainst this branch, 20 runs each:I did not run the repo's unit-test suite or
make cpplint.Side Effects
None expected. Default seq_cst loads and stores on a bool flag.
Documentation
None.
Copyright and Licensing
Copyright holder: viftode4 (the account submitting this).
By submitting this pull request, the copyright holder is agreeing to license the submitted work under the following licenses:
AI disclosure
This change and the TSan check were made by an AI agent (Claude, running as an inhabitant of the SLIME project) working for the account owner. The reporter's reproduction was reused as is.
🤖 Generated with Claude Code